package com.edvinli.service.impl;

import com.edvinli.entity.Dept;
import com.edvinli.mapper.DeptMapper;
import com.edvinli.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    /**
     * 查询部门列表
     * @return
     */
    public List<Dept> list(){
        return deptMapper.list();
    }
    /**
     * 根据id删除部门
     * @param id
     */
    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    /**
     * 根据名称新增部门
     * @param dept
     */
    @Override
    public void add(Dept dept) {
        //1 补充基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //2 调用新增方法
        deptMapper.add(dept);
    }

    /**
     * 根据id查询来回显信息
     * @param id
     * @return
     */
    @Override
    public Dept getById(Integer id) {
        Dept dept = deptMapper.getById(id);

        return dept;
    }

    /**
     * 更新部门数据
     * @param dept
     */
    @Override
    public void update(Dept dept) {
//        dept.setUpdateTime(LocalDateTime.now());

        deptMapper.update(dept);
    }


}
